<?php

$countPost = count($this->posts);
$category = ($this->category);
if( $this->infoSession->status == 'active' ):
    include 'views/inc/header.php';
    echo '<style>';
    include'public/css/postadd.css';
    echo '</style>';
    /* CLASS NO POST */
    if( $countPost == 0 ) {
        $no_post_class = null;
    } else {
        $no_post_class = ' class="post-user-profile"';
    }
    ?>
    <style>

        body
        {
            background-position: <?php echo $this->infoSession->bg_position; ?> 55px;
            background-attachment: <?php echo $this->infoSession->bg_attachment; ?>;

        <?php if( $this->infoSession->bg_attachment == 'fixed' ): ?>
            background-repeat: repeat repeat;
        <?php else: ?>
            background-repeat: no-repeat;
        <?php endif; ?>

            background-color: <?php echo $this->infoSession->bg_color; ?>;

        <?php if( $this->infoSession->bg != '' ): ?>
            background-image: url(<?php echo URL_BASE.'public/backgrounds/'.$this->infoSession->bg; ?>);
        <?php endif; ?>
        }

        body a,
        body a:hover { color: <?php echo $this->infoSession->color_link; ?>; }

        .icons { background-color: <?php echo $this->infoSession->color_link; ?>;}

    </style>
    <link href="<?php echo $_layoutParams['root_css']; ?>colorbox.css" rel="stylesheet" />
    <link href="<?php echo $_layoutParams['root_css']; ?>jquery-ui-1.8.2.custom.css" rel="stylesheet" />
    </head>
    <!-- Body -->
    <body data-max="<?php echo MAX_LENGTH; ?>" data-accept="<?php echo $_SESSION['LANG']['accept']; ?>" data-cancel="<?php echo $_SESSION['LANG']['cancel']; ?>">
    <?php include 'views/inc/profile_summary_inc.php'; ?>
    <!-- warpper_top_bar -->
    <div class="warpper_top_bar">
        <!-- inner_top_bar -->
        <header class="inner_top_bar">
            <!-- padding_class -->
            <div class="padding_class">
                <?php include 'views/inc/logo.php'; ?>
                <?php include 'views/inc/navigation.php'; ?>
            </div><!-- padding_class -->
        </header><!-- inner_top_bar -->
    </div><!-- warpper_top_bar -->

    <!-- page -->
    <div class="page">
        <!-- layout -->
        <section class="layout session">
            <div class="popout"></div>
            <!-- padding_class -->
            <div class="padding_class sessionClass">
                <div class="formSearchResp">
                    <form action="search/" class="formResponsive" method="get" id="search_engine" accept-charset="UTF-8">
                        <input id="btnItems" name="q" class="mention" type="text" placeholder="<?php echo $_SESSION['LANG']['search_word']; ?>" maxlength="100">
                    </form>
                </div>
                <!-- wrapper_grid -->
                <div class="wrapper_grid floatLeft banner_left">

                    <?php
                    //<---- * profile_static * --->
                  //  include 'views/inc/profile_static.php';

                    ?>

                    <!-- Grid 1 -->


                    <?php
                    //<---- * advertising * --->
                    include 'views/inc/advertising_left.php';
                    //<---- * who_follow * --->
                    //include 'views/inc/who_to_follow.php';
                    //<---- * trending * --->
                    include 'views/inc/trending.php';
                    ?>

                    <!-- Grid 1 -->
<!--                    <div class="grid_1">-->
                        <!-- container_grid -->
<!--                        <div class="container_grid about_pages">-->
                            <?php //include 'views/inc/footer_session.php'; ?>
                        <!--</div><!-- container_grid -->
                   <!-- </div><!-- Grid 1 -->


                </div><!-- wrapper_grid -->

                <!-- Grid 2 -->
                <div class="grid_2 floatLeft content_center">
                   <!--Add Post Here  -->
                    <?php                   ?>
                    <div class="">
                        <!-- container_grid -->
                        <div class="container_grid">

                            <div id="grid_post">
                                <h3 class="text-center margintop45">New Vote </h3>
                                <form style="border: none;" action="<?php echo URL_BASE; ?>public/ajax/upload.php" method="post" accept-charset="UTF-8" id="form_add_post" enctype="multipart/form-data">
                                    <textarea placeholder="What would you like to vote?" name="add_post" class="post_add" id="add_post"></textarea>
                                    <!--                                    <select id="category" style="float: left; width: 100%; margin-top: 10px; padding: 10px" name="category">-->
                                    <!--                                        <option value="0">Chosen one category!</option>-->
                                    <!---->
                                    <!--                                        --><?php //foreach($category as $cate){ ?>
                                    <!--                                            <option value="--><?//=$cate['id']?><!--">--><?//=$cate['title']?><!--</option>-->
                                    <!--                                      --><?php //  } ?>
                                    <!--                                    </select>-->

                                    <!-- choose type -->
                                    <div class="row">
                                        <div class="col50 col40">
                                            <h3 class="text-center">Choose Vote Method</h3>
                                        </div>
                                        <div class="col50 col60">
                                            <ul class="swicth-post-type-bg swicth-bg">
                                                <li class="groupHover" data-rel="swicth-bg-pool-hover"><p data-rel="group1 ">POLL</p></li>
                                                <li class="groupHover" data-rel="swicth-bg-rate-hover"><p data-rel="group2 ">RATE</p></li>
                                            </ul>
                                            <ul id="choose-option" class="choose-option">
                                                <li data-rel="1" class="group1 switch-group ">
                                                    <i class="sprite-ask binary-meta vs-button"></i>
<!--                                                    <p>Binary</p>-->
                                                </li>
                                                <li data-rel="2" class="group1 switch-group ">
                                                    <i class="sprite-ask multiple multiple-button"></i>
<!--                                                    <p> Multiple</p>-->
                                                </li>
                                                <li data-rel="3" class="group2 switch-group ">
                                                    <i class="sprite-ask  range-buton"></i>
<!--                                                    <p>Slider</p>-->
                                                </li>
                                                <li data-rel="4" class="group2 switch-group">
                                                    <i class="sprite-ask rating-button"></i>
<!--                                                    <p>Star</p>-->
                                                </li>
                                            </ul>
                                        </div>
                                    </div>
                                    <!--end choose type -->

                                    <!-- choose answer -->
                                    <div class="row">
                                        <div class="col50">
                                            <h3 class="left title-question text-center ">Your Answers</h3>
                                        </div>
                                        <div class="col50">
                                            <div id="bi_nary" class="binary" style="float: left;
width: 100%;
margin-top: 10px;
padding-top: 20px;
padding-bottom: 20px;
display: block;
background: rgb(238, 92, 41);">



                                                <input class="text-answer"  name="value_extra"  id="value_extra_1" type="text" name="value_extra_text" placeholder=" Type a unit here ">

                                                <div id="wrap-answer_1" class="wrap-answer">
                                                    <input class="text-answer val"  name="value"  id="value_1" type="text" name="binary_text" placeholder=" Your answer A ">
                                                    <button type="button"  class=" remove_option btn-remove-val" data_rm="1">X</button>
                                                </div>
                                                <div id="wrap-answer_2" class="wrap-answer">
                                                    <input class="text-answer val"  name="value"  id="value_2" type="text" name="binary_text" placeholder=" Your answer B ">
                                                    <button type="button" data_rm="2" class="remove_option btn-remove-val">X</button>
                                                </div>
                                            </div>
                                            <button   type="button" id="btn-add" class="btn-add-media" >Add+</button>
                                        </div>
                                    </div>
                                    <!--end choose answer -->


                                    <!-- choose Attach  -->
                                    <div class="row" style="margin-top: 17px;">
                                        <div class="col50">
                                            <h3 class="">Attach </h3>
                                        </div>
                                        <div class="col50">
                                            <div class="wrapper_media">
                                                <img id="loader_gif_img" class="deletePhoto img-cus-size">
                                                <input type="file" id="upload" title="<?php echo $_SESSION['LANG']['upload_image']; ?>" class="typeFile" name="photo" accept="image/*" />
                                                <!--                                        <div class="video_post" title="--><?php //echo $_SESSION['LANG']['add_video']; ?><!--"></div>-->
                                                <!--                                        <div class="song_post" title="--><?php //echo $_SESSION['LANG']['add_song']; ?><!--"></div>-->


                                            </div><!-- wrapper_media -->
                                        </div>
                                    </div>
                                    <!--end choose Attach  -->
                                    <!--button -->
                                    <div class="row check-disable">
                                            <button class="btn-add-post" data-title="<?php echo $_SESSION['LANG']['published_successfully']; ?>" id="button_add" <?php echo $no_post_class; ?> disabled="disabled" style="opacity: 0.5; cursor: default;" type="submit">
                                                <?php echo 'PUBLISH' ?>
                                            </button>

                                    </div>
                                    <!--end button -->


                                    <!--end post meta -->
                                    <div style="clear: both"></div>


                                    <input type="hidden" name="photoId" value="" id="photoId" />




                                    <div id="counter"></div>
                                    <input type="text" name="video_link" id="video_link" placeholder="<?php echo $_SESSION['LANG']['link_videos']; ?>" value="" />
                                    <input type="text" name="song_link" id="song_link" placeholder="<?php echo $_SESSION['LANG']['link_song']; ?>" value="" />


                                </form><!-- form -->

                                <input type="hidden" value="1" name="post_type" id="post_type" >
<!--                                <select style="float: left; width: 100%; margin-top: 10px; padding: 10px" name="post_type" id="post_type">-->
<!--                                    <option value="1">Binary</option>-->
<!--                                    <option value="2">Multiple</option>-->
<!--                                    <option value="3">Slider</option>-->
<!--                                    <option value="4">Star</option>-->
<!--                                </select>-->



                                <!-- Wrapper Preview -->
                                <div id="wrapper_preview">
                                    <div id="container_preview">
                                    </div>
                                </div><!-- Wrapper Preview -->
                            </div><!-- grid_post  -->
                        </div><!-- container_grid -->
                    </div><!-- Grid 1  -->

                    <!---End Add Post Here -->
                </div><!-- Grid 2 -->


                <!-- wrapper_grid -->
                <div class="wrapper_grid  floatRight banner_right">

                    <?php
                    include 'views/inc/advertising_right.php';
                    ?>




                </div><!-- wrapper_grid -->

            </div><!-- padding_class -->
        </section><!-- layout -->
        <!-- Grid 1 -->
        <div class="grid_1 footer_new">
            <!-- container_grid -->
            <div class="container_grid about_pages">
                <?php include 'views/inc/footer_session.php'; ?>
            </div><!-- container_grid -->
        </div><!-- Grid 1 -->
    </div><!-- page -->
    <div class="modal">
        <div id="content_modal">
        </div>
    </div>



    <script src="<?php echo $_layoutParams['root_js']; ?>jquery-1.7.1.min.js"></script>
    <script src="<?php echo $_layoutParams['root_js']; ?>jquery.easing.1.3.js"></script>
    <script src="<?php echo $_layoutParams['root_js']; ?>jquery.placeholder.1.1.1.min.js"></script>
    <script src="<?php echo $_layoutParams['root_js']; ?>jquery-ui-1.8.17.custom.min.js"></script>
    <script src="<?php echo $_layoutParams['root_js']; ?>functions.js"></script>
    <script src="<?php echo $_layoutParams['root_js']; ?>count.js"></script>
    <script src="<?php echo $_layoutParams['root_js']; ?>add.post.js"></script>
    <script src="<?php echo $_layoutParams['root_js']; ?>jquery.form.js"></script>
    <script src="<?php echo $_layoutParams['root_js']; ?>timeago/jqueryTimeago_<?php echo $_SESSION['lang']; ?>.js"></script>
    <script src="<?php echo $_layoutParams['root_js']; ?>jquery.colorbox.js"></script>
    <script src="<?php echo $_layoutParams['root_js']; ?>jquery.scroll.js"></script>
    <script src="<?php echo $_layoutParams['root_js']; ?>ajax.timeline.js"></script>
    <script src="<?php echo $_layoutParams['root_js']; ?>mentions.js"></script>

    <script type="text/javascript">

        $(".galeryAjax").colorbox({
            fixed: false,
            maxHeight: 550
        });

        <?php if( $countPost != 0 ): ?>

        $('.posts').scrollPagination({
            nop     : 10,
            offset  : 0,
            error   : '',
            delay   : 500,

            scroll  : true,
            query   : 0,
            file    : 'get_all_post.php',
            totalGlobal :  <?php echo $countPost; ?>
        });

        <?php endif; ?>

        jQuery(document).ready(function($) {
            $('#btn-add').hide();
            $('#value_extra_1').hide();
            $('.choose-option li').click(function(){
                $('#value_1').removeClass('checkNum');
                $('#value_2').removeClass('checkNum');
                var _post_type = $(this).attr('data-rel');
                $('.text-answer').val('');
                var detail = $('#add_post').val();
               if(_post_type == 1 || _post_type == 2 || _post_type == 3){
                   //disable post button
                   $(".btn-add-post").attr('disabled','disabled');
                   $('.title-question').show();
                   //end disable post button
               }else{
                   if(detail!= ''){
                       $(".btn-add-post").removeAttr('disabled');
                   }
               }


                $('#post_type').val(_post_type);
               // var _post_type = $('#post_type').find(":selected").val();
                if(_post_type == 3){
                    $('#value_extra_1').show();
                    $('#value_1').attr('placeholder','Enter min here').addClass('checkNum');
                    $('#value_2').attr('placeholder','Enter max here').addClass('checkNum');

                }else{
                    $('#value_extra_1').hide();
                    $('#value_1').attr('placeholder',' Your answer A ');
                    $('#value_2').attr('placeholder',' Your answer B');
                }

                if(_post_type == 2){
                    $('#btn-add').show();
                    $('.remove_option').show();
                    $('.binary').show();
                }
                else{
                    if(_post_type == 4){
                        $('.binary').hide();
                        $('.title-question').hide();
                    }else{
                        $('.binary').show();

                    }
                    $('#btn-add').hide();
                    $('.remove_option').hide();
                    var lenght = $('.binary').children('.wrap-answer').length;
                    for(var i = lenght; i> 2; i--){
                        $('#wrap-answer_'+i).remove();
                    }
                }

            });

            $(document).on('change','.checkNum',function(){
               var num = $(this).val();

                if(isNaN(num)){
                   alert('This field should be numeric');
                    $(this).val('').focus();
                }
            })

            $('.remove_option').hide();
            /*meta*/
//            $('#post_type').change(function(){
//
//            });

            $('#btn-add').click(function(e){
                var time = e.timeStamp;
                var lenght = $('.binary').children('.wrap-answer').length;
                var lenght_1 = lenght + 1;
                var  s = String.fromCharCode(lenght % 26 + 97).toUpperCase();

                var html = '<div class="wrap-answer" id="wrap-answer_'+lenght_1+'"> ' +
                    '  <input class="text-answer val"  name="value"  id="value_1" type="text" name="binary_text" placeholder=" Your answer '+s+' ">' +
                    '<button type="button" data_rm="'+lenght_1+'" class="remove_option btn-remove-val">X</button>' +
                    '</div>';
                var count = $('#bi_nary').find('.wrap-answer').length;
                if(count < 5){
                    $('#bi_nary').append(html);
                    $(".btn-add-post").attr('disabled','disabled');
                }

//                $(".btn-add-post").text('can t click');

            })
            /*end meta*/


            //====== TIME AGO

            //=== COUNTER
         $('#add_post').live('hover', function(){
                if ($(this).data('hascharcount') == undefined) {
                    $(this).data('hascharcount', true).charCount({ allowed: <?php echo MAX_LENGTH; ?>, warning: 10, css: 'counter_2' });
                }
            });

            $('#reply_post').live('hover', function(){
                if ($(this).data('hascharcount') == undefined) {
                    $(this).data('hascharcount', true).charCount({ allowed: <?php echo MAX_LENGTH; ?>, warning: 10 });
                }
            });

            //=== PLACEHOLDER
            $(function(){
                $(':input[placeholder]').placeholder();
            });


            //=================== * UPLOAD  * ===============//
            $('#upload').live('change', function(){
                $('<div id="loader_gif"></div>').insertBefore('#upload');

                $('#button_add').attr({'disabled' : 'true'}).css({'opacity':'0.5','cursor':'default'});
                $('#add_post').attr({'disabled' : 'true'}).css({'opacity':'0.5'});


                (function() {

                    $("#form_add_post").ajaxForm({

                        dataType : 'json',
                        success:  function(e)
                        {
                            if( e ) {
                                $('#add_post').removeAttr('disabled').css({'opacity':'1'});
                                if( e.error == 1 ) {
                                    $('#loader_gif').remove();
                                }

                                $('#wrapper_preview').show();
                                $('#container_preview').html( ''+ e.output +'' ).show();
                                $('#upload').val('');

                                if( e.error == 0 ) {
                                    $('#loader_gif').css({background:'url("<?php echo URL_BASE; ?>/public/img/upload.png") center center no-repeat #FFF'}).addClass('deletePhoto').attr( 'data',e.photo ).attr( 'title','<?php echo $_SESSION['LANG']['delete_image']; ?>' );
                                    $('#loader_gif_img').attr('src',"<?php echo URL_BASE; ?>thumb_fixed/250-250-tmp/"+ e.photo );
                                    $('#wrapper_preview').show();
                                    $('#photoId').val(e.photo);
                                    $('#button_add').removeAttr('disabled').css({'opacity':'1','cursor':'pointer'});
                                }

                            } else {
                                jAlert('<?php echo $_SESSION['LANG']['error']; ?>');
                                $('#upload').val('');
                                $('#button_add').removeAttr('disabled').css({'opacity':'1','cursor':'pointer'});
                                $('#loader_gif').remove();

                            }
                        }//<----- SUCCESS

                    }).submit();
                })(); //<--- FUNCTION %
            });//<--- LIVE

            $('.remove_option').live('click',function(){
                var id_remove = $(this).attr('data_rm');
                $('#wrap-answer_'+id_remove).remove();
            })

            //===== DELETE PHOTO
            $(".deletePhoto").live('click',function(){
                //=== PARAM
                var element     = $(this);
                var id          = element.attr("data");
                var info        = 'token_id=' + id;
                var add_post_   = $('#add_post').val();
                var video_link_ = $('#video_link').val();

                $.ajax({
                    type: "GET",
                    url: "<?php echo URL_BASE; ?>public/ajax/delete_id_photo.php",
                    data: info,
                    success: function(output){
                        if( output == 'TRUE' )
                        {
                            if( add_post_ == 0 && video_link_ == 0 )
                            {
                                $('#button_add').attr({'disabled' : 'true'}).css({'opacity':'0.5','cursor':'default'});
                            }

                            $('#photoId').val('');
                            $('#loader_gif_img').attr('src','');
                            element.fadeOut('fast',function(){
                                element.remove();
                            });//<-- FUNCTION
                        }

                    }

                });//<-- AJAX
            });//<--- CLICK

        });//<-------- * DOM * ------>


    </script>
    </body>
    </html>
<?php
else:

    session_destroy();

endif; ?>

